
//
// 101216 - AH - Created.
// 110205 - AH - (Bien) toString().
// 110217 - AH - (Bien) getTagCount().
// 110605 - AH - (Garage) getSoekrat() which is to be used for matching.
// 110612 - AH - toString() now print SoekratName().
// 110615 - AH - setSoekratName(String).
// 120228 - AH - (Zen *) getTags().
//

package org.soekrat.engine.mine;

import org.soekrat.AttributeObject;
import org.soekrat.engine.SoekratName;

/**
 * <p>
 *   A resource in a
 *   {@link Mine}.
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC) 
 */
public final class Resource extends AttributeObject 
{
  private SoekratName m_sname;
  
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param name Resource name.
   */
  public Resource(String name){ setSoekratName(name); }
  
  /**
   * <p>
   *   Gets the 
   *   {@link SoekratName}.
   * </p>
   * @return {@code SoekratName}.
   */
  public SoekratName getSoekratName(){ return m_sname; }
  
  /**
   * <p>
   *   Sets name.
   * </p>
   * @param name Name.
   */
  public void setSoekratName(String name)
  { 
    if (name==null)
    {
      throw new NullPointerException(name);
    }
    
    m_sname=new SoekratName(name);
    setName(m_sname.getPure());
  }
  
  @Override
  public String toString()
  {
    Tags tags=(Tags)getAttribute("tags");
    StringBuilder sb=new StringBuilder();
    sb.append("name=").append(getSoekratName());
    if (tags!=null) sb.append(" tags=").append(tags);
    return sb.toString();
  }
  
  /**
   * <p>
   *   Gets the number of 
   *   {@link Tags}s {@code this} has.
   * </p>
   * @return Count.
   */
  public int getTagCount()
  {
    Tags tags=(Tags)getAttribute("tags");
    return tags==null ? 0 : tags.size();
  }
  
  /**
   * <p>
   *   Gets
   *   {@link Tags}.
   * </p>
   * @return {@link Tags} or {@code null} if has no tags.
   */
  public Tags getTags(){ return (Tags)getAttribute("tags"); }
  
  /**
   * <p>
   *   The empty array shared.
   * </p>
   */
  public static final Resource[] EMPTY_ARRAY=new Resource[0];
  
}
